export class UserModel {
  userId: number
  token: string
  userName: string
  name: string

  constructor() {
    this.userId = Number.parseInt(window.localStorage.getItem('userId') || '0')
    this.token = localStorage.getItem('token') || ''
    this.userName = localStorage.getItem('userName') || ''
    this.name = localStorage.getItem('name') || ''
  }

  login(userId: number, token: string, userName: string, name: string) {
    this.userId = userId
    this.token = token
    this.userName = userName
    this.name = name
    localStorage.setItem('userId', this.userId.toString())
    localStorage.setItem('token', this.token)
    localStorage.setItem('userName', this.userName)
    localStorage.setItem('name', this.name)
  }

  logout() {
    this.userId = 0
    this.token = ''
    this.userName = ''
    this.name = ''
    localStorage.removeItem('userId')
    localStorage.removeItem('token')
    localStorage.removeItem('userName')
    localStorage.removeItem('name')
  }
}
